package com.sourcemuch.im.caiba;

import android.content.Context;
import android.util.Log;

import com.sourcemuch.im.caiba.wxapi.WXUserInfo;

import cn.wildfire.chat.app.MyApp;
import cn.wildfire.chat.app.extendsion.classes.RegionFetcherRequest;
import cn.wildfire.chat.app.extendsion.ui.LightThenNotifyPhone;
import cn.wildfire.chat.app.main.MainActivity;

/**
 * Create by HEKE, 2019/8/19 10:10
 * TODO 配置第三方版本推送服务器主进程程序对象
 */
public class CaiBaChatApp extends MyApp {

    /**
     * modify by HEKE , 2019/8/20 20:21
     * TODO 信推常驻后台服务绑定信息
     */
    public SuperService.CaibaBinder caibaBinder;

    /**
     * modify by HEKE , 2019/8/20 20:35
     * TODO 主界面的上下文
     */
    public Context mainActivityContext;

    /**
     * modify by HEKE , 2019/8/21 9:52
     * TODO 锁屏等状态下操作对象
     */
    public LightThenNotifyPhone lightThenNotifyPhone;

    /**
     * modify by HEKE , 2019/8/23 10:18
     * TODO 多个开启程序请求数据
     */
    public RegionFetcherRequest regionFetcher;

    /**
     * 手机屏幕是否锁定
     */
    public boolean isScreenLocked;

    /**
     * 手动捆绑刷新事件对象
     */
    public ManumotiveIBinder manumotiveIBinder;

    /**
     * 微信信息
     */
    public WXUserInfo wxUserInfo;

    @Override
    public void onCreate() {
        super.onCreate();
        manumotiveIBinder = new ManumotiveIBinder();
        regionFetcher = new RegionFetcherRequest(this);
    }

    /**
     * modify by HEKE , 2019/8/20 20:34
     * TODO 绑定主界面山西该文
     */
    public void setMainActivityContext(Context mainActivityContext) {
        this.mainActivityContext = mainActivityContext;
    }

    /**
     * modify by HEKE , 2019/8/20 20:34
     * TODO 绑定服务
     */
    public void bindCaibaBinder(SuperService.CaibaBinder caibaBinder) {
        this.caibaBinder = caibaBinder;
        this.caibaBinder.bindPushObject(wfcUIKit);
        if (mainActivityContext != null) {
            ((MainActivity) mainActivityContext).bindListener();
        }
    }

    /**
     * modify by HEKE , 2019/8/21 9:54
     * TODO 获取亮屏与通知对象
     */
    public LightThenNotifyPhone getLightThenNotifyPhone() {
        return lightThenNotifyPhone;
    }

    @Override
    public void onLowMemory() {
        super.onLowMemory();
        // 显示悬浮窗口
        if (lightThenNotifyPhone != null) {
            lightThenNotifyPhone.showWindow();
        }
    }

    /**
     * modify by HEKE , 2019/8/24 15:32
     * TODO 具体处理手机推送信息实现函数
     */
    @Override
    public void receiveMessage(String message, int type) {
        super.receiveMessage(message, type);
        if (mainActivityContext != null) {
            ((MainActivity) mainActivityContext).receiveMessage(message, type);
        } else {
            Log.e("###### RMsg Prepare ", "type : " + type + "  message : " + message);
        }
    }

    /**
     * modify by HEKE , 2019/8/24 15:32
     * TODO 来自于野火通道通知
     */
    public void receiveMessage(String message, String title) {
        if (mainActivityContext != null) {
            ((MainActivity) mainActivityContext).receiveMessage(message, title);
        }
    }

}
